﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace RCREEE.Library.Entities
{
    public class Project
    {

        #region Private varible

        private int _ProjectId;
        private int _LanguageCode;
        private string _Name;
        private string _Place;
        private int _ExecutingAgencyId;
        private string _ExecutingAgency;
        private string _Description;
        private bool _IsElectrical;
        private bool _IsThermal;
        private int _OperationYear;
        private bool _IsImplemented;
        private int _SectorId;
        private string _SectorName;
        private string _PickupsInstalledArea;
        private float _InstalledCapacity;
        private float _EnergyProducedPerYearRate;
        private int _CountryId;
        private string _CountryName;
        private int _TypeId;
        private string _ProjectType;
        private int _EntityId;
        private int _Record;
        private int _ProjectGroupId;
        private string _ProjectGroupName;
        private int _StatusId;
        private string _StatusName;


        private string _ConstructionCompanies;

     


        private int roweffect;
    
        List<Project> Lproject = new List<Project>();
     
        #endregion

        #region public properties

        public int ProjectId
        {
            get { return _ProjectId; }
            set { _ProjectId = value; }
        }

        public int LanguageCode
        {
            get { return _LanguageCode; }
            set { _LanguageCode = value; }
        }

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public string Place
        {
            get { return _Place; }
            set { _Place = value; }
        }

        public int ExecutingAgencyId
        {
            get { return _ExecutingAgencyId; }
            set { _ExecutingAgencyId = value; }
        }

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        public bool IsElectrical
        {
            get { return _IsElectrical; }
            set { _IsElectrical = value; }
        }

        public bool IsThermal
        {
            get { return _IsThermal; }
            set { _IsThermal = value; }
        }

        public int OperationYear
        {
            get { return _OperationYear; }
            set {
                 _OperationYear = value; 
            }
        }

        public bool IsImplemented
        {
            get { return _IsImplemented; }
            set { _IsImplemented = value; }
        }

        public string SectorName
        {
            get { return _SectorName; }
            set { _SectorName = value; }
        }

        public string PickupsInstalledArea
        {
            get { return _PickupsInstalledArea; }
            set { _PickupsInstalledArea = value; }
        }

        public float InstalledCapacity
        {
            get { return _InstalledCapacity; }
            set { _InstalledCapacity = value; }
        }

        public float EnergyProducedPerYearRate
        {
            get { return _EnergyProducedPerYearRate; }
            set { _EnergyProducedPerYearRate = value; }
        }

        public int CountryId
        {
            get { return _CountryId; }
            set { _CountryId = value; }
        }

        public int TypeId
        {
            get { return _TypeId; }
            set { _TypeId = value; }
        }

        public int EntityId
        {
            get { return _EntityId; }
            set { _EntityId = value; }
        }
        public int Record
        {
            get { return _Record; }
            set { _Record = value; }
        }
        public int ProjectGroupId
        {
            get { return _ProjectGroupId; }
            set { _ProjectGroupId = value; }
        }
        public string CountryName
        {
            get { return _CountryName; }
            set { _CountryName = value; }
        }
        public string ProjectType
        {
            get { return _ProjectType; }
            set { _ProjectType = value; }
        }
        public string ProjectGroupName
        {
            get { return _ProjectGroupName; }
            set { _ProjectGroupName = value; }
        }
        public string ExecutingAgency
        {
            get { return _ExecutingAgency; }
            set { _ExecutingAgency = value; }
        }

        public int SectorId
        {
            get { return _SectorId; }
            set { _SectorId = value; }
        }

        public int StatusId
        {
            get { return _StatusId; }
            set { _StatusId = value; }
        }
        public string StatusName
        {
            get { return _StatusName; }
            set { _StatusName = value; }
        }
        public string ConstructionCompanies
        {
            get { return _ConstructionCompanies; }
            set { _ConstructionCompanies = value; }
        }
        #endregion

        #region Constructor

        public Project()
        {

        }


        #endregion

        #region private Method

        #endregion

        #region public Method
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<TinyItem> GetListItemsLookUps(int LanguageCode)
        {
            try
            {
                return DataManager.GetListItemsLookUps(LanguageCode);
            }
            catch (Exception) { return null; }
        }
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<TinyItem> GetListItemProjectEntity(int LanguageCode)
        {
            try
            {
                return DataManager.GetListItemProjectEntity(LanguageCode);
            }
            catch (Exception) { return null; }
        }
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<TinyItem> GetListExecutingEntity(int LanguageCode)
        {
            try
            {
                return DataManager.GetListExecutingEntity(LanguageCode);
            }
            catch (Exception) { return null; }
        }
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public DataTable SelectAllProject(int LanguageCode,int EntityId)
        {
            try { return DataManager.SelectAllProject(LanguageCode,EntityId); }
            catch (Exception)
            { return null; }
        }
        /// <summary>
        /// call function SelectProjectByCountry from DataManager
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <param name="CountryId"></param>
        /// <param name="EntityId"></param>
        /// <returns></returns>

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public DataTable SelectAllprojectByCountry(int LanguageCode, int CountryId, int EntityId)
        {
            try { return DataManager.SelectProjectsByCountry(LanguageCode, CountryId, EntityId); }
            catch (Exception)
            { return null; }
        }

        /// <summary>
        /// calling function of SelectAllProjectCountries from DataManager to return list of countries
        /// </summary>
        /// <param name="EntityId"></param>
        /// <param name="LanguageCode"></param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<TinyItem> SelectAllProjectCountries(int EntityId, int LanguageCode)
        {
            try { return DataManager.SelectAllProjectCountries(EntityId, LanguageCode); }
            catch (Exception)
            { return null; }
        }
        /// <summary>
        /// calling function from DataManager to return one project 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public DataTable SelectprojectbyId(int LanguageCode, int ProjectId,int Record)
        {
            try { return DataManager.SelectprojectById(LanguageCode, ProjectId,Record); }
            catch (Exception)
            {
                return null;
            }
        }

        #region webFunction
        public List<Project> SelectAllProjectweb(int LanguageCode, int EntityId)
        {
            try
            {
               ;
                DataTable DtProject = new DataTable();
                DtProject = DataManager.SelectAllProject(LanguageCode, EntityId);
                for (int i = 0; i < DtProject.Rows.Count; i++)
                {
                    Lproject[i].ProjectId = Convert.ToInt32(DtProject.Rows[i]["ProjectId"]);
                    Lproject[i].LanguageCode = Convert.ToInt32(DtProject.Rows[i]["LanguageCode"]);
                    Lproject[i].Name = Convert.ToString(DtProject.Rows[i]["Name"]);
                    Lproject[i].Place = Convert.ToString(DtProject.Rows[i]["Place"]);
                    Lproject[i].ExecutingAgencyId = Convert.ToInt32(DtProject.Rows[i]["ExecutingAgencyId"]);
                    Lproject[i].Description = Convert.ToString(DtProject.Rows[i]["Description"]);
                    Lproject[i].IsElectrical = Convert.ToBoolean(DtProject.Rows[i]["IsElectrical"]);
                    Lproject[i].IsImplemented = Convert.ToBoolean(DtProject.Rows[i]["IsImplemented"]);
                    Lproject[i].IsThermal = Convert.ToBoolean(DtProject.Rows[i]["IsThermal "]);
                    Lproject[i].OperationYear = Convert.ToInt32(DtProject.Rows[i]["OperationYear"]);
                    Lproject[i].SectorName = Convert.ToString(DtProject.Rows[i]["Sector"]);
                    Lproject[i].PickupsInstalledArea = Convert.ToString(DtProject.Rows[i]["PickupsInstalledArea"]);
                    Lproject[i].InstalledCapacity = (float)DtProject.Rows[i]["InstalledCapacity"];
                    Lproject[i].EnergyProducedPerYearRate = (float)DtProject.Rows[i]["EnergyProducedPerYearRate"];
                    Lproject[i].CountryId = Convert.ToInt32(DtProject.Rows[i]["CountryId"]);
                    Lproject[i].EntityId = Convert.ToInt32(DtProject.Rows[i]["EntityId"]);
                    Lproject[i].TypeId = Convert.ToInt32(DtProject.Rows[i]["TypeId"]);
                    Lproject[i].ProjectGroupId = Convert.ToInt32(DtProject.Rows[i]["ProjectGroupId"]);
                    Lproject[i].ProjectType = Convert.ToString(DtProject.Rows[i]["ProjectType"]);
                    Lproject[i].CountryName = Convert.ToString(DtProject.Rows[i]["CountryName"]);
                    Lproject[i].ExecutingAgency = Convert.ToString(DtProject.Rows[i]["ExecutingAgency"]);
                    Lproject[i].ProjectGroupName = Convert.ToString(DtProject.Rows[i]["ProjectGroupName"]);
                    Lproject[i].StatusName = Convert.ToString(DtProject.Rows[i]["StatusName "]);
                    Lproject[i].ConstructionCompanies = Convert.ToString(DtProject.Rows[i]["ConstructionCompanies "]);
                    Lproject[i].SectorId = Convert.ToInt32(DtProject.Rows[i]["SectorId"]);
                    Lproject[i].StatusId = Convert.ToInt32(DtProject.Rows[i]["StatusId"]);
                }
                return Lproject;
            }
            catch (Exception e)
            { return null; }
        }

        public  List<Project> SelectAllprojectByCountryweb(int LanguageCode, int CountryId, int EntityId)
        {
            try
            {
                DataTable DtProject = new DataTable();
                DtProject = DataManager.SelectProjectsByCountry(LanguageCode, CountryId, EntityId);

            for (int i = 0; i < DtProject.Rows.Count; i++)
            {
                Lproject[i].ProjectId = Convert.ToInt32(DtProject.Rows[i]["ProjectId"]);
                Lproject[i].LanguageCode = Convert.ToInt32(DtProject.Rows[i]["LanguageCode"]);
                Lproject[i].Name = Convert.ToString(DtProject.Rows[i]["Name"]);
                Lproject[i].Place = Convert.ToString(DtProject.Rows[i]["Place"]);
                Lproject[i].ExecutingAgencyId = Convert.ToInt32(DtProject.Rows[i]["ExecutingAgencyId"]);
                Lproject[i].Description = Convert.ToString(DtProject.Rows[i]["Description"]);
                Lproject[i].IsElectrical = Convert.ToBoolean(DtProject.Rows[i]["IsElectrical"]);
                Lproject[i].IsImplemented = Convert.ToBoolean(DtProject.Rows[i]["IsImplemented"]);
                Lproject[i].IsThermal = Convert.ToBoolean(DtProject.Rows[i]["IsThermal "]);
                Lproject[i].OperationYear = Convert.ToInt32(DtProject.Rows[i]["OperationYear"]);
                Lproject[i].SectorName = Convert.ToString(DtProject.Rows[i]["SectorName"]);
                Lproject[i].PickupsInstalledArea = Convert.ToString(DtProject.Rows[i]["PickupsInstalledArea"]);
                Lproject[i].InstalledCapacity = (float)DtProject.Rows[i]["InstalledCapacity"];
                Lproject[i].EnergyProducedPerYearRate = (float)DtProject.Rows[i]["EnergyProducedPerYearRate"];
                Lproject[i].CountryId = Convert.ToInt32(DtProject.Rows[i]["CountryId"]);
                Lproject[i].EntityId = Convert.ToInt32(DtProject.Rows[i]["EntityId"]);
                Lproject[i].TypeId = Convert.ToInt32(DtProject.Rows[i]["TypeId"]);
                Lproject[i].ProjectGroupId = Convert.ToInt32(DtProject.Rows[i]["ProjectGroupId"]);
                Lproject[i].ProjectType = Convert.ToString(DtProject.Rows[i]["ProjectType"]);
                Lproject[i].CountryName = Convert.ToString(DtProject.Rows[i]["CountryName"]);
                Lproject[i].ExecutingAgency = Convert.ToString(DtProject.Rows[i]["ExecutingAgency"]);
                Lproject[i].ProjectGroupName = Convert.ToString(DtProject.Rows[i]["ProjectGroupName"]);
                Lproject[i].StatusName = Convert.ToString(DtProject.Rows[i]["StatusName "]);
                Lproject[i].ConstructionCompanies = Convert.ToString(DtProject.Rows[i]["ConstructionCompanies "]);
                Lproject[i].SectorId = Convert.ToInt32(DtProject.Rows[i]["SectorId"]);
                Lproject[i].StatusId = Convert.ToInt32(DtProject.Rows[i]["StatusId"]);
              
            }
            return Lproject;
            }
            catch (Exception)
            { return null; }
        }
        public Project SelectprojectbyIdweb(int LanguageCode, int ProjectId, int Record)
        {
            try
            {
                Project project = new Project();
                DataTable DtProject = new DataTable();
                DtProject = DataManager.SelectprojectById(LanguageCode, ProjectId, Record);

            project.ProjectId = Convert.ToInt32(DtProject.Rows[0]["ProjectId"]);
            project.LanguageCode = Convert.ToInt32(DtProject.Rows[0]["LanguageCode"]);
            project.Name = Convert.ToString(DtProject.Rows[0]["Name"]);
            project.Place = Convert.ToString(DtProject.Rows[0]["Place"]);
            project.ExecutingAgencyId = Convert.ToInt32(DtProject.Rows[0]["ExecutingAgencyId"]);
            project.Description = Convert.ToString(DtProject.Rows[0]["Description"]);
            project.IsElectrical = Convert.ToBoolean(DtProject.Rows[0]["IsElectrical"]);
            project.IsImplemented = Convert.ToBoolean(DtProject.Rows[0]["IsImplemented"]);
            project.IsThermal = Convert.ToBoolean(DtProject.Rows[0]["IsThermal "]);
            project.OperationYear = Convert.ToInt32(DtProject.Rows[0]["OperationYear"]);
            project.SectorName = Convert.ToString(DtProject.Rows[0]["SectorName"]);
            project.PickupsInstalledArea = Convert.ToString(DtProject.Rows[0]["PickupsInstalledArea"]);
            project.InstalledCapacity = (float)DtProject.Rows[0]["InstalledCapacity"];
            project.EnergyProducedPerYearRate = (float)DtProject.Rows[0]["EnergyProducedPerYearRate"];
            project.CountryId = Convert.ToInt32(DtProject.Rows[0]["CountryId"]);
            project.EntityId = Convert.ToInt32(DtProject.Rows[0]["EntityId"]);
            project.TypeId = Convert.ToInt32(DtProject.Rows[0]["TypeId"]);
            project.ProjectGroupId = Convert.ToInt32(DtProject.Rows[0]["ProjectGroupId"]);
            project.Record = Convert.ToInt32(DtProject.Rows[0]["R"]);
            project.ProjectType = Convert.ToString(DtProject.Rows[0]["ProjectType"]);
            project.CountryName = Convert.ToString(DtProject.Rows[0]["CountryName"]);
            project.ExecutingAgency = Convert.ToString(DtProject.Rows[0]["ExecutingAgency"]);
            project.ProjectGroupName = Convert.ToString(DtProject.Rows[0]["ProjectGroupName"]);
           project.StatusName = Convert.ToString(DtProject.Rows[0]["StatusName "]);
           project.ConstructionCompanies = Convert.ToString(DtProject.Rows[0]["ConstructionCompanies "]);
            project.SectorId = Convert.ToInt32(DtProject.Rows[0]["SectorId"]);
            project.StatusId = Convert.ToInt32(DtProject.Rows[0]["StatusId"]);
              
            return project;
            
            
            }
            catch (Exception)
            {
                return null;
            }
        }
        #endregion

        /// <summary>
        /// calling GetEntities from DataManager
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <returns> list of items ID,Name</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public List<TinyItem> GetEntity(int LanguageCode)
        {
            try { return DataManager.GetEntity(LanguageCode); }
            catch (Exception)
            {
                return null;
            }
        }
        public static DataTable SelectProjectById2(int projectId)
        {
            try { return DataManager.SelectProjectById2(projectId); }
            catch (Exception)
            {
                return null;
            }
        }
        /// <summary>
        /// calling GetCounties from DataManager
        /// </summary>
        /// <param name="LanguageCode"> from session</param>
        /// <returns> list of items ID,Name</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public List<TinyItem> GetCountries(int LanguageCode)
        {
            try { return DataManager.GetCountries(LanguageCode); }
            catch (Exception)
            {
                return null;
            }
        }
        //[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        //public List<TinyItem> GetAllCountries(int LanguageCode)
        //{
        //    try { return DataManager.GetALLCountries(LanguageCode); }
        //    catch (Exception)
        //    {
        //        return null;
        //    }
        //}
       [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public List<TinyItem> GetLanguageCode()
        {
            try { return DataManager.GetLanguageCode(); }
            catch (Exception)
            {
                return null;
            }
        }
        /// <summary>
        /// calling GetCContacts from DataManager
        /// </summary>
        /// <param name="LanguageCode"> from session</param>
        /// <returns> list of items ID,Name</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public List<TinyItem> GetContacts(int LanguageCode, int CountryId, int EntityId)
        {
            try { 
                //List<TinyItem> 
                return DataManager.GetContacts(LanguageCode, CountryId, EntityId); }
            catch (Exception)
            {
                return null;
            }
        }
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public List<TinyItem> GetListProjectSector(int LanguageCode)
        {
            try { return DataManager.GetListProjectSector(LanguageCode); }
            catch (Exception)
            {
                return null;
            }
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public List<TinyItem> GetListProjectStatus(int LanguageCode)
        {
            try { return DataManager.GetListProjectStatus(LanguageCode); }
            catch (Exception)
            {
                return null;
            }
        }
        /// <summary>
        /// calling function from DataManager to insert one record of project
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool InsertProject(Project project)
        {
            try
            {
                roweffect = DataManager.InsertProject(project);
                return roweffect == 1;
            }
            catch (Exception) { return roweffect == 0; }
        }
         [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
     
        public static List<TinyItem> GetListItemProjectTypes(int ParentId, int LanguageCode)
        {
            try { return DataManager.GetListItemProjectTypes(ParentId, LanguageCode); }
            catch (Exception)
            {
                return null;
            }
        }
        /// <summary>
        /// calling function from DataManager to update one record of project
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool UpdateProject(Project project)
        {
            try
            {
                roweffect = DataManager.UpdateProject(project);
                return roweffect == 1;
            }
            catch (Exception)
            { return roweffect == 0; }
        }

        /// <summary>
        ///  calling function from DataManager to Delete one record of project
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool Deleteproject(Project project)
        {
            try
            {
                roweffect = DataManager.DeleteProject(project.ProjectId, project.LanguageCode);
                return roweffect == 1;
            }
            catch (Exception)
            { return roweffect == 0; }
        }


        #endregion

        #region Override

        /// <summary>
        /// override Method to return Name of project
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name;
        }
        #endregion
    }
}
